/**
 *    @file       workthread.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/12/2014 09:48:51 AM
 *
 *    @author     Theophilus (), wangtf418@gmail.com
 */
#ifndef _SF_WORKTHREAD_H_
#define _SF_WORKTHREAD_H_
#include "threadcore.h"
#include "srvdef.h"
#include "message.h"
#include "argument.h"
#include "timer.h"

class workthread : public threadcore
{
public:
	workthread(bf_uint32_t type, bf_uint32_t size, bf_uint32_t index, const comargs *args);
	virtual ~workthread();

public:
	//----inherit from thread core----
	//virtual bf_int_t init() = 0;	///< init before thread starts
	//virtual bf_int_t run() = 0;
	//----inherit from thread core----

public:
	virtual void init_run() = 0;	///< init after thread starts
	virtual void uninit_run() = 0;	///< uninit after thread stops

public:
	virtual bf_int_t put_msg(message *msg);
	virtual bf_size_t get_msgq_len();

public:
	void send_msg(bf_int32_t type, bf_uint32_t index, bf_uint64_t taskid, bf_uint32_t msgtype, msgbody *body, bf_uint64_t src_taskid = DEFAULT_TASKID);

public:
	inline bf_uint32_t get_thd_type() {return m_thd_type;}
	inline bf_uint32_t get_grp_size() {return m_grp_size;}
	inline bf_uint32_t get_thd_index() {return m_thd_index;}

protected:
	virtual bf_int_t proc_msg(message *msg);
	virtual bf_int_t add_timer(interval_timer &itimer);
	virtual bf_int_t add_timer(point_timer &ptimer);

protected:
	bf_uint32_t m_thd_type;
	bf_uint32_t m_grp_size;
	bf_uint32_t m_thd_index;
	comargs *m_args;
};

#endif


